#ifndef _CENTITY_H_
	#define _CENTITY_H_
#include <vector>
 
#include "CAnimation.h"
#include "CSurface.h"
#include "CArea.h"
#include "CFPS.h"
#include "CCamera.h"
#include <Box2D\Box2D.h>

enum ENTITY_TYPE{
	ENTITY_TYPE_GENERIC = 0,
	ENTITY_TYPE_PLAYER
};
enum ENTITY_FLAG{
	ENTITY_FLAG_NONE = 0,

	ENTITY_FLAG_GRAVITY = 0x00000001,
	ENTITY_FLAG_GHOST   = 0x00000002,
	ENTITY_FLAG_MAPONLY = 0x00000004,
};
enum ENTITY_STATE{
	IDLE		= 0x00000001,
	MOVE_LEFT	= 0x00000002,
	MOVE_RIGHT	= 0x00000004,

	CLIMP_IDLE	= 0x00000008,
	CLIMP_UP	= 0x00000016,
	CLIMP_DOWN	= 0x00000032,

	LIE			= 0x00000064,

	SHOOT_IDLE	= 0x00000128,
	SHOOT_RUN	= 0x00000256,
	SHOOT_UP	= 0x00000512,
	SHOOT_DOWN	= 0x00001024,

	JUMP_LEFT= 0x00002048,
	JUMP_RIGHT= 0x00004096,
};

class CEntity
{
protected:

	CAnimation Anim_Control;
	SDL_Surface* Surf_Entity;
	

	float SpeedX;
	float SpeedY;

	float AccelX;
	float AccelY;

	//Animation-ii Zurgiin column. State-s hamaarch oorchilno.
	int CurrentFrameCol;
	int CurrentFrameRow;// iluu ch ym shig :)
	
	//Animation-d zoriulsan file-iin size-iin dotor bga
	//zurgiin offset-g n hassan bdal. Collision tootsohod
	//zurgiin gadnah huree bish "Player"-iin hamar n hanand
	//hurehed l zogsohod ashiglana. 
	int Col_X;
	int Col_Y;
	int Col_Width;
	int Col_Height;

	bool CanJump;
	int JumpHeight;

public:
	b2Body* b2_body;

	static std::vector<CEntity*> EntityList;

	float X;
	float Y;
	int Width;
	int Height;

	bool MoveLeft;
	bool MoveRight;
	bool isShooting;

	int Type;
	bool Dead;
	int Flags;

	float MaxSpeedX;
	float MaxSpeedY;

	int AnimState;
	
	CEntity(void);

	virtual bool OnLoad(char* File, int Width, int Height, int MaxFrames);
	virtual void OnLoop();
	virtual void OnRender(SDL_Surface* Surf_Display);
	virtual void OnCleanup();
	virtual void OnAnimate();
	virtual bool OnCollision(CEntity* Entity);

	void OnMove(float MoveX, float MoveY);
	void StopMove();
	bool Collides(int oX, int oY, int oW, int oH);
	bool PosValid(int NewX, int NewY);
	bool PosValidTile(CTile* Tile);
	bool PosValidEntity(CEntity* Entity, int NewX, int NewY);

	bool Jump();
	bool isGrounded();
};

class CEntityCol
{
public:
	static std::vector<CEntityCol> EntityColList;

	CEntity* EntityA;
	CEntity* EntityB;

	CEntityCol();

};

#endif